package com.gitee.wsl.compose.image

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import com.gitee.wsl.annotation.ExperimentalApi

 interface ImageLoader {

    @OptIn(ExperimentalApi::class)
    @Composable
    fun load(model: Any): ImageData?

    companion object{
        @OptIn(ExperimentalApi::class)
        val default:ImageLoader = DefaultImageLoader
    }

}

@ExperimentalApi
internal object DefaultImageLoader: ImageLoader {

    @Composable
    override fun load(model: Any): ImageData? = null

}

@OptIn(ExperimentalApi::class)
 val LocalImageLoader: ProvidableCompositionLocal<ImageLoader> = staticCompositionLocalOf {
    DefaultImageLoader
}

@ExperimentalApi
@Immutable
class ImageData(
     val painter: Painter,
     val contentDescription: String? = null,
     val alignment: Alignment = Alignment.Center,
     val contentScale: ContentScale = ContentScale.Fit,
     val modifier: Modifier = Modifier.fillMaxWidth()
)